package cn.lz.cloud.param.springmvc;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 作者 E-mail:
 * @date 创建时间：2017年3月7日 上午10:12:34
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
@Controller
public class Testcontroller {
	@RequestMapping("/test")
	public String list(HttpServletRequest request) {
		request.setAttribute("abc", "abc");
		return "test";
	}

	@RequestMapping("/testhttp")
	@ResponseBody
	public String list1(HttpServletRequest request) throws ParseException, IOException{
		// 创建Httpclient对象
		CloseableHttpClient httpclient = HttpClients.createDefault(); 
		
		// 创建http GET请求
        HttpGet httpGet = new HttpGet("http://localhost:8801/find-sysAppGroup?uuid=11310P0G9KGIJ003");
		
        CloseableHttpResponse response = null;
        String content=null;
            try {
				response = httpclient.execute(httpGet);
			} catch (IOException e) {
				e.printStackTrace();
			}
            finally{
            	 // 判断返回状态是否为200
                if (response.getStatusLine().getStatusCode() == 200) {
                    content = EntityUtils.toString(response.getEntity(), "UTF-8");
                	System.out.println("内容：" + content);
                	
                }
            }
         return content;  
        
        //return "testhttp";
	}
}
